/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;

import Models.User;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author trang_000
 */
public class UserDAO {
    Connection con = DBFactory.createConnection("dormitoryv2");
     public  List<User> getUser(){
        ResultSet rs = null;
        List<User> results = new ArrayList<>();
        String sqlcommand ="SELECT * FROM user  ";
        try {
            Statement st = con.createStatement();
            rs=st.executeQuery(sqlcommand);
            while (rs.next()) {
                
                int userID= rs.getInt(1);
                String userString = rs.getString(2);
                String password = rs.getString(3);
                User user = new User(userID, userString, password);
                System.out.println(user.getUserName());
                results.add(user);
            } 
        } catch (SQLException ex) {
           
        }
        
        
        return results;
        
    } 
    
}
